<!--
 * @Description: 查询条件
 * @Autor: dyx
 * @Date: 2023-02-15 11:26:59
 * @LastEditTime: 2023-02-15 17:06:56
-->
<template>
  <div>
    <el-row class="JADP-common-search-box" :gutter="16">
      <el-form @submit.native.prevent>
        <el-col :span="6" v-if="type == 1 || type == 3 || type == 4">
          <el-form-item label="班级名称">
            <el-input
              v-model="className"
              placeholder="请选择班级"
              readonly
              @click.native.stop="clazzClick"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click.native.stop="clazzClick"
                >查询</el-button
              >
            </el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="6" v-if="type == 2">
          <el-form-item label="课程名称">
            <el-input
              v-model="coursemanageName"
              placeholder="请选择班级"
              readonly
              @click.native.stop="courseClick"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click.native.stop="courseClick"
                >查询</el-button
              >
            </el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="6" v-if="type == 3 || type == 4">
          <el-form-item label="课件名称">
            <el-input
              v-model="coursewareName"
              placeholder="请选择班级"
              readonly
              @click.native.stop="coursewareClick"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click.native.stop="coursewareClick"
                >查询</el-button
              >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="type == 4">
          <el-form-item label="讲师名称">
            <el-input
              v-model="teacherName"
              placeholder="请选择班级"
              readonly
              @click.native.stop="teacherClick"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click.native.stop="teacherClick"
                >查询</el-button
              >
            </el-input>
          </el-form-item>
        </el-col>
        <template v-if="showAll">
          <el-col :span="6">
            <el-form-item label="评分方式">
              <el-select
                v-model="query.manageid"
                placeholder="请先选择班级再选择评分方式"
              >
                <el-option label="分值评价" value="1"></el-option>
                <el-option label="自定义评价" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </template>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="initData()"
              >查询</el-button
            >
            <el-button icon="el-icon-refresh-right" @click="reset()"
              >重置</el-button
            >
            <div style="display: inline-block; margin-left: 10px;">
              <el-button
                type="text"
                icon="el-icon-arrow-down"
                @click="showAll = true"
                v-if="!showAll"
              >
                展开
              </el-button>
              <el-button
                type="text"
                icon="el-icon-arrow-up"
                @click="showAll = false"
                v-else
              >
                收起
              </el-button>
            </div>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <ClazzTable ref="clazzTable" @currentRow="currentRow" />
    <CourseTable ref="courseTable" @currentRow="coursemanageEvent" />
    <CoursewareTable ref="coursewareTable" @currentRow="CoursewareEvent" />
    <TeacherTable ref="teacherTable" @currentRow="TeacherEvent" />
  </div>
</template>
<script>
import ClazzTable from "../../components/clazzTable.vue";
import CourseTable from "./courseTable.vue";
import CoursewareTable from "./coursewareTable.vue";
import TeacherTable from "./TeacherTable";
import request from "@/utils/request";
export default {
  name: "",
  props: {
    type: {
      // 1-培训班  2-课程 3-课件  4-讲师
      type: [String, Number],
      default: ""
    }
  },
  components: {
    ClazzTable,
    CourseTable,
    CoursewareTable,
    TeacherTable
  },
  data() {
    return {
      showAll: true,
      className: "",
      coursemanageName: "",
      coursewareName: "",
      teacherName: "",
      evaluationOptions: [],
      query: {
        coursemanageid: "",
        manageid: "", // 评分方式
        // categoretype: "", //分类
        coursewareid: "", //课件id
        teacherid: "" //讲师id
      },
      queryName: "",
      typeV: this.type
    };
  },
  methods: {
    initData() {
      // console.log(this.query, "this.query");
      // if (this.type == "1" && !this.query.coursemanageid) {
      //   this.$message.warning("请先选择班级");
      //   return;
      // } else if (this.type == "2") {
      // } else if (this.type == "3" && !this.query.coursewareid) {
      //   this.$message.warning("请先选择课件");
      //   return;
      // } else if (this.type == "4" && !this.query.teacherid) {
      //   this.$message.warning("请先选择讲师");
      //   return;
      // }
      // if (!this.query.manageid) {
      //   this.$message.warning("请选择评分方式");
      //   return;
      // }

      if (this.type == "1") {
        if (!this.query.coursemanageid) {
          this.$message.warning("请先选择班级");
          return;
        }
      } else if (this.type == "2") {
      } else if (this.type == "3") {
        if (!this.query.coursemanageid) {
          this.$message.warning("请先选择班级");
          return;
        } else if (!this.query.coursewareid) {
          this.$message.warning("请先选择课件");
          return;
        }
      } else if (this.type == "4") {
        if (!this.query.coursemanageid) {
          this.$message.warning("请先选择班级");
          return;
        } else if (!this.query.coursewareid) {
          this.$message.warning("请先选择课件");
          return;
        }else if (!this.query.teacherid) {
          this.$message.warning("请先选择讲师");
          return;
        }
      }

      if (!this.query.manageid) {
        this.$message.warning("请选择评分方式");
        return;
      }

     
      this.$emit("initData", this.query);
    },
    reset() {
      this.query = {
        coursemanageid: "",
        manageid: ""
      };
      this.coursemanageName = "";
      this.initData();
    },
    clazzClick() {
      this.$refs.clazzTable.visible = true;
    },
    courseClick() {
      this.$refs.courseTable.visible = true;
    },
    coursewareClick() {
      this.$refs.coursewareTable.visible = true;
    },
    teacherClick() {
      this.$refs.teacherTable.visible = true;
    },
    currentRow(val) {
      this.query.coursemanageid = val.id;
      this.className = val.classname;
      // this.getEvaluationOptions();
    },
    coursemanageEvent(id, name) {
      this.query.coursemanageid = id;
      this.coursemanageName = name;
      // this.getEvaluationOptions();
    },
    CoursewareEvent(id, name) {
      this.query.coursewareid = id;
      this.coursewareName = name;
      // this.getEvaluationOptions();
    },
    TeacherEvent(id, name) {
      this.query.teacherid = id;
      this.teacherName = name;
      // this.getEvaluationOptions();
    },
    getEvaluationOptions() {
      if (!this.query.coursemanageid) {
        this.$message.warning("请先选择班级");
        return;
      }
      let categoreid;
      if (this.type == "1") {
        this.query.categoretype = 1;
        categoreid = "896b47acaad64ae59d8bcaf86e6fba18";
      } else if (this.type == "2") {
        this.query.categoretype = 2;
        categoreid = "59c767291601498b9b584a8fc09ab833";
      } else if (this.type == "3") {
        this.query.categoretype = 3;
        categoreid = "41dce5f0b6794ff4a73552e92d750d13";
      } else {
        this.query.categoretype = 4;
        categoreid = "37ede04af69d425b8dd97024e08c4ca3";
      }
      // request({
      //   url: "/api/xy_pj_student/Xy_pj_student/getRatingManage",
      //   method: "get",
      //   data: {
      //     categoreid, //分类id
      //     coursemanageid: this.query.coursemanageid, //班级 课程 课时 老师id
      //     categoretype // 1-培训班  2-课程 3-课件  4-讲师
      //   }
      // }).then(res => {
      //   this.evaluationOptions = res.data;
      // });
    }
  }
};
</script>
<style scoped lang="scss"></style>
